package state;

import java.util.ArrayList;
import java.util.List;

public class AudioPlayer {
    State state;
    List<String> playList;
    int currentSongIndex;

    public AudioPlayer() {
        this.state = new ReadyState(this);
        this.playList = new ArrayList<>();
        this.currentSongIndex = 0;
    }

    public void changeState(State state) {
        this.state = state;
    }

    public State getState() {
        return state;
    }

    public void addSong(String song) {
        playList.add(song);
    }

    public int playListSize() {
        return playList.size();
    }

    public void clickLock() {
        state.clickLock();
    }

    public void clickPlay() {
        state.clickPlay();
    }

    public void clickNext() {
        state.clickNext();
    }

    public void clickPrevious() {
        state.clickPrevious();
    }

    public void startPlay() {
        System.out.println("Playing song: " + playList.get(currentSongIndex));
    }

    public void stopPlay() {
        System.out.println("Stopping song: " + playList.get(currentSongIndex));
    }

    public void nextSong() {
        currentSongIndex++;
        if (currentSongIndex == playList.size()) {
            currentSongIndex = 0;
        }
        System.out.println("Playing song: " + playList.get(currentSongIndex));
    }

    public void previousSong() {
        currentSongIndex--;
        if (currentSongIndex < 0) {
            currentSongIndex = playList.size() - 1;
        }
        System.out.println("Playing song: " + playList.get(currentSongIndex));
    }

}
